<%@ page language="java" import="cn.hutool.core.date.DateUnit" pageEncoding="UTF-8" %>
<%@ page import="cn.hutool.core.date.DateUtil" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%--验证移动短信验证码--%>
<%
    BaseBean baseBean = new BaseBean();
    String sjh = Util.null2String(request.getParameter("sjh"));
    String yzm = Util.null2String(request.getParameter("yzm"));
    RecordSet rs = new RecordSet();
    baseBean.writeLog(">>>>>getSmsYzm>>>>>sjh=" + sjh + ",yzm=" + yzm);
    Map<String, Object> apidatas = new HashMap<String, Object>();
    boolean status = false;
    String message = "";
    try {
        String sql = "select id,to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') curdate,yzmscsj from uf_sjyzjm where yzm=? and sjh=?";
        rs.executeQuery(sql, yzm, sjh);
        if (rs.next()) {
            String id = Util.null2String(rs.getString("id"));
            if ("".equals(id)) {
                message = "验证码错误";
            } else {
                String curdate = Util.null2String(rs.getString("curdate"));
                String yzmscsj = Util.null2String(rs.getString("yzmscsj"));
                long diffmin = getDiffMinute(yzmscsj, curdate);
                if (diffmin > 600) {
                    message = "验证码已过期";
                } else {
                    message = "验证码正确";
                    status = true;
                }
            }
        } else {
            message = "验证码错误";
        }

    } catch (Exception e) {
        baseBean.writeLog(">>>>>getSmsYzm>>>>>Exception=" + e);
    }
    apidatas.put("status", status);
    apidatas.put("message", message);
    out.print(JSONObject.toJSONString(apidatas));

%>
<%!
    public static long getDiffMinute(String begintime, String endtime) {
        Date data1 = DateUtil.parse(begintime);
        Date date2 = DateUtil.parse(endtime);
        return DateUtil.between(data1, date2, DateUnit.SECOND);
    }

%>



